package com.liang.rabbitmqspringboot.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DirectRabbitMqConfiguration {
//: 声明注册direct模式的交换机

    @Bean
    public DirectExchange directExchange(){
    return new DirectExchange("direct_order_exchange",true,false);
        }

// 2: 声明队列 sms.fanout.queue email.fanout.queue,duanxin.fanout.queue
    @Bean
    public Queue smsQueueDirect(){
        System.out.println("9999999999999999999999999999999999999999999999999999999999999999");
        return new Queue("sms.direct.queue",true);
    }

    @Bean
    public Queue duanxinQueueDirect(){
        System.out.println("888888888888888888888888888888888888888888888888888888888888");
        return new Queue("duanxin.direct.queue",true);
    }

    @Bean
    public Queue emailQueueDirect(){
        System.out.println("11111111111111111111111111111111111111111111");
        return new Queue("email.direct.queue",true);
    }

// 3: 完成绑定关系(队列和交换机完成绑定关系)
    @Bean
    public Binding smsBingdingDirect(){
        return BindingBuilder.bind(smsQueueDirect()).to(directExchange()).with("sms");
    }

    @Bean
    public Binding duanxinBingdingDirect(){
        return BindingBuilder.bind(duanxinQueueDirect()).to(directExchange()).with("duanxin");
    }
    @Bean
    public Binding emailBingdingDirect(){
        return BindingBuilder.bind(emailQueueDirect()).to(directExchange()).with("email");
    }


}
